(function() {
    let url = decodeURI(location.search).slice(1).split('&');
    let newUrl = {};
    url.forEach(item => {
        let key = item.split('=')[0];
        let value = item.split('=')[1];
        newUrl[key] = value;
    });
    console.log(newUrl);
    //请求 面包屑 api 渲染
    fetch('http://chst.vip:1234/api/getcategorybyid?categoryid=' + newUrl.categoryid).then(body => body.json()).then(res => {
        let result = res.result;
        console.log(result);
        result.forEach(item => {
            let hrefStr = `
            <a href="../pages/index1.html">首页</a> > <a href="../pages/category.html">全部分类</a> >  <a href="../pages/bijia.html?title=${item.category}&ategoryid=${item.categoryId}">${item.category}</a> > <a href="JavaScript:;">当前页面</a>
            `;
            $('.position').html(hrefStr);
        })
    });
    //请求 产品详情 api  渲染
    fetch('http://chst.vip:1234/api/getproduct?productid=' + newUrl.productid).then(body => body.json()).then(res => {
        let result = res.result;
        // console.log(result);
        let htmlStr = '';
        result.forEach(item => {
            htmlStr += `
            <div class="ico">
            ${item.productImg}
            </div>
            <h2>${item.productName}</h2>
            <div class="dec">
            
                <span>当前最低: ¥6000</span>
                <span>优选评论: 6000条</span>
            </div>
            <div class="shop">
            ${item.bjShop}
            </div>
            `
        });
        $('.content').html(htmlStr);
    });
    //请求评论 api  渲染
    fetch('http://chst.vip:1234/api/getproductcom?productid=' + newUrl.productid).then(body => body.json()).then(res => {
        let result = res.result;
        // console.log(result);
        let htmlStr = '';
        result.forEach(item => {
            htmlStr += `
            <dl>
                    <dt>
                        <span>${item.comName}</span>
                        <span>${item.comTime}</span>
                    </dt>
                    <dd>
                        ${item.comContent}
                    </dd>
                </dl>
            `
        });
        $('.comment').html(htmlStr)
    });
})()